#4 题目要求：
#在当前目录新建目录img, 里面包含10个文件, 10个文件名各不相同(X4G5.png)
#将当前img目录所有以.png结尾的后缀名改为.jpg.


import random
import string
import os
def code(len = 10):
    l = random.sample(string.sdcii_letters+string.digits,len)
    return  ''.join(l)

def creat():
    l = {code() for i in range(100)}
    os.mkdir('img')
    for name in l:
        os.mknod('img/' + name + '/.png')

def m(dirname, old, new,):
    png = [filename for filename in os.listdir(dirname) if filename.endswith(old)]
    base = [os.path.splitext(filename)[0] for filename in png ]
    for filename in base:
        oldname = os.path.join(dirname,filename+old)
        newname = os.path.join(dirname,filename+new)
        os.rename(oldname,newname)

m('img', '.png', '.jpg')